package acm.华中农业;


import 左哥算法.compare.comparator.MyComparator;
import 左哥算法.compare.华中农业.Main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class B {
    static {
        Graph graph = new Graph(8);
        String[] ddl = "25 4 41 60 13 2 55 38".split(" ");
        String[] edges = {
                "1 2",
                "2 3",
                "2 6",
                "2 8",
                "3 4",
                "4 5",
                "4 7",
        };
        graph.build(ddl);
        for (String edge : edges) {
            graph.insert(edge.split(" "));
        }
        System.out.println(graph.search(2, 4, 48));
        System.out.println(graph.search(8, 23, 58));
    }

    public static void fun(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] read = null;
        read = in.readLine().split(" ");
        int n = Integer.parseInt(read[0]);
        int m = Integer.parseInt(read[1]);
        Graph graph = new Graph(n);
        read = in.readLine().split(" ");
        graph.build(read);
        for (int i = 1; i < n; i++) {
            read = in.readLine().split(" ");
            graph.insert(read);
        }
        while (m-- > 0) {
            read = in.readLine().split(" ");
            graph.clear();
            switch (read[0]) {
                case "2":
                    System.out.println(graph.search(
                            Integer.parseInt(read[1]),
                            Integer.parseInt(read[2]),
                            Integer.parseInt(read[3])
                    ));
                    continue;
                case "1":
                    graph.update(Integer.parseInt(read[1]), Integer.parseInt(read[2]));
            }
        }
    }
    static class Graph {
        boolean[][] map;
        int[] val;

        public Graph(int size) {
            this.map = new boolean[size + 1][size + 1];  //next
            this.val = new int[size + 1];
        }

        public void build(String[] node) {
            for (int i = 0; i < node.length; i++) {
                val[i + 1] = Integer.parseInt(node[i]);
            }
        }

        public void insert(String[] edge) {
            int root = Integer.parseInt(edge[0]);
            int child = Integer.parseInt(edge[1]);
            map[root][child] = true;
        }

        public void update(int i, int ddl) {
            val[i] = ddl;
        }

        public int search(int root, int L, int R) {
            if (set.contains(root) || val[root] < L || val[root] > R) {  //该树走不了
                return 0;
            }
            int res = 1;
            set.add(root);
            for (int i = 1; i < map[root].length; i++) {
                if (map[root][i]) {
                    res += search(i, L, R);
                }
            }
            return res;
        }

        Set<Integer> set = new HashSet<>();

        public void clear() {
            set.clear();
        }
    }





//    public static void main(String[] args) {
//        Random rand = new Random();
//        new MyComparator(container -> {
//            Integer a = rand.nextInt(10) + 1;
//            Integer b = rand.nextInt(10) + 1;
//            container.add(a).addEnd(b)
//                    .nextInts(a, 100);
//            for (int i = 1; i < a; i++) {
//                container.nextInts(2,a);
//            }
//            for (int i = 0; i < b; i++) {
//                if (rand.nextBoolean()){
//                    container.add(1).next(a).next(100);
//                }else {
//                    int l = rand.nextInt(60);
//                    int r = rand.nextInt(40)+l;
//                    container.add(2).next(a).add(l).add(r);
//                }
//            }
//        }).compare(args1 -> {
//            try {
//                fun(args1);
//            } catch (IOException e) {
//                throw new RuntimeException(e);
//            }
//        },Main::main);
//    }
}
